/* 
 * File:   CBallCircle.cpp
 * Author: qlogic
 * 
 * Created on February 3, 2014, 2:44 PM
 */

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include "CBallCircle.h"

CBallCircle::CBallCircle()
{
    init();
}

CBallCircle::CBallCircle(const CBallCircle& orig)
{
    m_ptCenter = orig.m_ptCenter;
    m_radius = orig.m_radius;
}

CBallCircle::~CBallCircle()
{
}

void CBallCircle::init()
{
    m_ptCenter = cv::Point2f(0, 0);
    m_radius = 0.0;

    m_ptCenterNear = cv::Point2f(0, 125);
    m_ballRadiusNear = 105.0;
    m_ptCenterFar = cv::Point2f(0, 400);
    m_ballRadiusFar = 25.0;
    m_distanceToFarEdgeOfView = 14.4;
    m_tolerancePercentForRadius = 0.05;
}

bool CBallCircle::isSmallerThanBallAtCenterLocationInView() const
{
    // ranges from 0 at near to 1 at far
    float pctDownRange = ((float)(m_ptCenter.x - m_ptCenterNear.x)) / ((float)(m_ptCenterFar.x - m_ptCenterNear.x));
    float expectedRadius = m_ballRadiusNear - (pctDownRange * ((m_ballRadiusNear - m_ballRadiusFar)));
    expectedRadius += (m_tolerancePercentForRadius * expectedRadius);
    return (m_radius < expectedRadius);
}

bool CBallCircle::isLargerThanBallAtCenterLocationInView() const
{
    // ranges from 0 at near to 1 at far
    float pctDownRange = ((float)(m_ptCenter.x - m_ptCenterNear.x)) / ((float)(m_ptCenterFar.x - m_ptCenterNear.x));
    float expectedRadius = m_ballRadiusNear - (pctDownRange * ((m_ballRadiusNear - m_ballRadiusFar)));
    expectedRadius -= (m_tolerancePercentForRadius * expectedRadius);
    return (m_radius > expectedRadius);
}
